package com.ckd.flyingtrip.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.androidkun.adapter.BaseAdapter;
import com.ckd.flyingtrip.R;

import java.util.List;

public class MeBatteryAdapter extends RecyclerView.Adapter<MeBatteryAdapter.MyHolder> {

    private Context context;
    private List<String> list;
    public OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    public MeBatteryAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyHolder(LayoutInflater.from(context).inflate(R.layout.item_me_battery_recyclerview, null));
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        holder.num.setText("电池" + (position + 1));
        holder.textView.setText(list.get(position));

        holder.btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener.onItemClick(v, position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyHolder extends RecyclerView.ViewHolder {
        TextView num, textView, btn;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            num = itemView.findViewById(R.id.item_me_battery_recyclerview_num);
            textView = itemView.findViewById(R.id.item_me_battery_recyclerview_textView);
            btn = itemView.findViewById(R.id.item_me_battery_recyclerview_btn);
        }
    }
}
